// 节流
export const throttle = (func, delay) => {
  let timer = null
  return function () {
    const _this = this
    // 已经有在执行的东西就return
    if (timer) {
      return
    }
    timer = setTimeout(() => {
      func.apply(_this)
      timer = null
    }, delay)
  }
}
// 防抖
export function debounce (func, delay) {
  let timer = null
  return function () {
    // 这里好像放里面才对
    const context = this

    if (timer) clearTimeout(timer)
    // 有lock就不让他2s后发生
    timer = setTimeout(() => {
      func.apply(context)
    }, delay)
  }
}
